$(function() {
	var status=window.location.search.substr(1)
	status=status.substring(status.length-1)
	if(status==0){
		$(".btn-check").html("待确定");
		$(".btn-check").attr('disabled','1');
		$(".btn-check").removeClass("am-btn-primary tpl-btn-bg-color-success ");
		$('.btn-check').addClass('layui-btn-disabled');
	}else if(status==1){
		$(".btn-check").html("确定");
		$(".btn-check").removeClass("am-btn-primary tpl-btn-bg-color-success ");
		$('.btn-check').addClass('layui-btn-disabled');
	
	}
	var arr;
	$.ajax({
		url: "/assets/json/AccountCheckingdetails.json",
		dataType: "json",
		success: function(res) {
			console.log(res.data)
			arr = res.data;
			var a;
			var money = 0;
			for(var i = 0; i < arr.length; i++) {

				var item = res.data[i];
				a += `<tr >
							<td>${item.id1}</td>
							<td>${item.check}</td>
							<td>${item.time1}</td>
							<td>${item.site1}</td>
							<td>${item.site1}</td>
							<td>${item.name1}</td>
							<td>${item.name2}</td>
							<td>${item.ordertype}</td>
							<td>${item.usecar}</td>
							<td>${item.cartype1}</td>
							<td>${item.cartype2}</td>
							<td>${item.driver}</td>
							<td>${item.carid}</td>
							<td>${item.money}</td>
							<td>
								<div class="tpl-table-black-operation">
									<a href="javascript:;" class="tpl-table-black-operation-del">
										<i class="am-icon-trash"></i> 无效
									</a>
								</div>
							</td>
						</tr>`;
				if(item.isuse == 1) {
					money += item.money;
				};
			}

			$('.total').html(money);
			//失效
			$('tbody').html(a);
			$('.tpl-table-black-operation .tpl-table-black-operation-del').on('click', function() {
				var that = this;

				layer.open({
					content: '失效原因：<input type="text"/>',
					btn: ['确定', '取消'],
					yes: function(index, layero) {
							var index1 = $(that).parent().parent().parent().index();
							$(that).parent().parent().siblings().eq(1).html('无效');
							arr[index1].isuse = 0;
							var momey1 = 0;
							for(var j = 0; j < arr.length; j++) {
								if(arr[j].isuse == 1) {
									momey1 += arr[j].money;
								}
							}
							console.log(momey1);
							$('.total').html(momey1);
							 layer.close(index);
					}
				});

			})
			
		}
	})
	$('.btn-check').on('click',function(){
		console.log(1)
		$(this).html("待确定")
		$(this).removeClass("am-btn-primary tpl-btn-bg-color-success ")
		$(this).addClass('layui-btn-disabled')
	})
	$('.btn-back').on('click',function(){
		window.history.back(-1); 
	})
})